package com.itheima.blog.admin.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.blog.admin.dao.TWebNavbarMapper;
import com.itheima.blog.admin.entity.TBanner;
import com.itheima.blog.admin.entity.TWebNavbar;

import com.itheima.blog.admin.service.ITWebNavbarService;
import com.itheima.common.domain.PageReqDto;
import com.itheima.common.domain.PageResDto;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 门户网站首页导航栏 服务实现类
 * </p>
 *
 * @author blog
 * @since 2023-07-11
 */
@Service
public class TWebNavbarServiceImpl extends ServiceImpl<TWebNavbarMapper, TWebNavbar> implements ITWebNavbarService {

    @Override
    public void addRoute(TWebNavbar tWebNavbar) {
        tWebNavbar.setCreateTime(LocalDateTime.now());
        tWebNavbar.setUpdateTime(LocalDateTime.now());
        this.save(tWebNavbar);
    }

    @Override
    public void updateByRouteId(TWebNavbar tWebNavbar) {
        /*lambdaUpdate()
                .eq(TWebNavbar::getId,tWebNavbar.getId())
                .set(TWebNavbar::getName,tWebNavbar.getName())
                .set(TWebNavbar::getSummary,tWebNavbar.getSummary())
                .set(TWebNavbar::getPath,tWebNavbar.getPath())
                .set(TWebNavbar::getIsShow,tWebNavbar.getIsShow())
                .set(TWebNavbar::getSort,tWebNavbar.getSort())
                .set(TWebNavbar::getUpdateTime, LocalDateTime.now())
                .update();*/
        tWebNavbar.setUpdateTime(LocalDateTime.now());
        this.updateById(tWebNavbar);
    }

    @Override
    public void deleteRoute(Long id) {
        this.removeById(id);
    }

    @Override
    public PageResDto<TWebNavbar> findRouteList(PageReqDto pageReqDto) {
        //获取分页条件
        Integer page = pageReqDto.getPage();
        Integer size = pageReqDto.getSize();
        int i = (page - 1) * size;
        //获取分页数据
        Page<TWebNavbar> tWebNavbarPage = lambdaQuery().orderByDesc(TWebNavbar::getSort)
                .page(new Page<>(i, size));

        List<TWebNavbar> records = tWebNavbarPage.getRecords();
        return new PageResDto<>(pageReqDto,tWebNavbarPage.getTotal(), records);
    }


}
